package ltd.hxya.novel.crawl.controller;


import ltd.hxya.novel.common.bean.Result;
import ltd.hxya.novel.common.exception.NovelGlobalException;
import ltd.hxya.novel.common.bean.ResultEnum;
import ltd.hxya.novel.crawl.bean.CrawlVo;
import ltd.hxya.novel.crawl.service.ICrawlRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hty
 * @since 2022-10-16
 */
@RestController
@RequestMapping("/crawl/rule")
public class CrawlRuleController {

    @Autowired
    private ICrawlRuleService crawlRuleService;

    @PostMapping("/updateAndAddCrawlRule")
    public Result updateAndAddCrawlRule(@RequestBody CrawlVo crawlVo){
        if (crawlVo.getCrawlRule()==null){
            throw new NovelGlobalException(ResultEnum.CRAWL_RULE_ERROR.getCode(), ResultEnum.CRAWL_RULE_ERROR.getMsg());
        }
        crawlRuleService.updateAndAddCrawlRule(crawlVo);
        return Result.success();
    }
}
